//operate task
function stopOneTask() {
	$(".stop-task").click(function() {
		debugger
		$.ajax({
			url : "../rest/task/stopOneTask",
			data : {
				"taskName" : $(this).data("stop")
			},
			dataType : "json",
			method : "post",
			success : function(data) {

			}
		})
	})
}

// create task list table
function createTableForTask() {
	var tableStructure = "<table  class='table table-bordered' id='viewTask'><tr><th>Task Name</th><th>Status</th><th>Task Log</th><th>Stop</th></tr></table>";

	$("#taskList").append(tableStructure);

}

function addtaskList() {
	$.ajax({
		url : "../rest/task/manageTask",
		dataType : "json",
		// method : "post",
		success : function(data) {
			debugger
			createTableForTask();
			$.each(data, function(k, v) {
				debugger
				$("#viewTask").append(
						"<tr><td>" + k + "</td><td>" + v
								+ "</td><td><input type=\"button\" class=\"task-log\" value=\"task log\" data-log=\"" + k + "\""
								+ "></td><td><input type=\"button\" class=\"stop-task\" value=\"stop\" data-stop=\"" + k + "\"" + "></td>"
								+ "</tr>");
			});
			stopOneTask();
		}
	});
}

$(function() {
	addtaskList();
})
